#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 110, M = 310;

struct Record {
    string id;
    int score;
    int local_rank;
    int local_num;
    int final_rank;

    bool operator< (const Record & r) const {
        if (score == r.score) return id < r.id;
        return score > r.score;
    }
}records[N * M];


int n, m, idx;

unordered_map<int, int> score_hash, hash2; 
map<int, int, greater<int>> hash1;

inline void solution() {
    
    cin >> n;

    for (int i = 1; i <= n; i ++ ) {
        cin >> m;
        int t = idx;
        hash1.clear();
        hash2.clear();
        for (int j = 0; j < m; j ++) {
            cin >> records[idx].id >> records[idx].score;
            records[idx].local_num = i;
            hash1[records[idx].score] ++ ;
            idx ++ ;
        }


        int r = 0;
        for (auto & x : hash1) {
            hash2[x.first] = r + 1;
            r += x.second;
        }


        for (int j = t, r = 0; j < idx; j ++, r ++ ) {
            if (hash2.find(records[j].score) == hash2.end()) 
                hash2[records[j].score] = r + 1;
            records[j].local_rank = hash2[records[j].score];
        }
        
    }
    cout << idx << endl;
    sort(records, records + idx);
    for (int i = 0; i < idx; i ++ ) {
        if (score_hash.find(records[i].score) == score_hash.end()) 
            score_hash[records[i].score] = i + 1;
        records[i].final_rank = score_hash[records[i].score];

        cout << records[i].id << " " << records[i].final_rank << " " << records[i].local_num << " " << records[i].local_rank << endl;
    }
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}


// 需要灵活使用hash表
// 排名涉及到分数，同分数排名问题最好使用hash表来存储分数